﻿using Microsoft.AspNetCore.Http;
using System.Web;

namespace WeixinSDK.Work.Common
{
    /// <summary>
    /// 浏览器公共类
    /// </summary>
    public static class BrowserUtility
    {
        /// <summary>
        /// 判断是否在微信内置浏览器中
        /// </summary>
        /// <param name="accessor">IHttpContextAccessor</param>
        /// <returns>true：在微信内置浏览器内。false：不在微信内置浏览器内。</returns>
        public static bool SideInWeixinBrowser(this IHttpContextAccessor accessor)
        {
            var userAgent = accessor.HttpContext.Request.Headers["User-Agent"].ToString();
            if (userAgent != null  && userAgent.Contains("MicroMessenger"))
            {
                return true;//在微信内部
            }
            else
            {
                return false;//在微信外部
            }
        }
    }
}
